package com.yy.bolg.util.hikfirecloud;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;

import java.util.HashMap;
import java.util.Map;

/**
 * 海康消防云SDK
 * @author enmaoFu
 * @date 2024-12-13
 */
public class HikFireCloud {

    {
        ArtemisConfig.host = "open.hikfirecloud.com"; 		// artemis网关服务器ip端口
        ArtemisConfig.appKey = "23816941"; 					// 秘钥appkey
        ArtemisConfig.appSecret = "ys5VAMuod38CR6ZFuw8D";	// 秘钥appSecret
    }

    /**
     * 能力开放平台的网站路径，路径不用修改，就是/artemis
     */
    private static final String ARTEMIS_PATH = "/artemis";

    /**
     * 分页查询设备
     */
    @SuppressWarnings("serial")
    public String getDeviceList(Map<String, String> paramMap) {
        String url = ARTEMIS_PATH + "/api/device/v2/getDevice";
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", url);
            }
        };
        String result = ArtemisHttpUtil.doPostStringArtemis(path, JSON.toJSONString(paramMap), null, null, "application/json");
        return result;
    }

    /**
     * 分页查询传感器
     */
    @SuppressWarnings("serial")
    public String getSensorList(Map<String, String> paramMap) {
        String url = ARTEMIS_PATH + "/api/channel/v2/getSensor";
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", url);
            }
        };
        String result = ArtemisHttpUtil.doPostStringArtemis(path, JSON.toJSONString(paramMap), null, null, "application/json");
        JSONObject jsonObject = JSONObject.parseObject(result);
        if(jsonObject.get("code") == "0"){

        }
        return result;
    }

    /**
     * 分页查询设备状态
     */
    @SuppressWarnings("serial")
    public String getFireDeviceStatusList(Map<String, String> paramMap) {
        String url = ARTEMIS_PATH + "/api/device/v2/getFireDeviceStatus";
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", url);
            }
        };
        String result = ArtemisHttpUtil.doPostStringArtemis(path, JSON.toJSONString(paramMap), null, null, "application/json");
        return result;
    }

    /**
     * 分页查询历史监测数据
     */
    @SuppressWarnings("serial")
    public static String getHistoryMonitor(Map<String, String> paramMap) {
        String url = ARTEMIS_PATH + "/api/businessData/v2/getHistoryMonitor";
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", url);
            }
        };
        String result = ArtemisHttpUtil.doPostStringArtemis(path, JSON.toJSONString(paramMap), null, null, "application/json");
        return result;
    }

    /**
     * 分页查询监测数据
     */
    @SuppressWarnings("serial")
    public static String getMonitor(Map<String, String> paramMap) {
        String url = ARTEMIS_PATH + "/api/businessData/v2/getMonitor";
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", url);
            }
        };
        String result = ArtemisHttpUtil.doPostStringArtemis(path, JSON.toJSONString(paramMap), null, null, "application/json");
        return result;
    }

    /**
     * 分页查询预警数据
     */
    @SuppressWarnings("serial")
    public static String getAlarmList(Map<String, String> paramMap) {
        String url = ARTEMIS_PATH + "/api/businessData/v2/getAlarm";
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", url);
            }
        };
        String result = ArtemisHttpUtil.doPostStringArtemis(path, JSON.toJSONString(paramMap), null, null, "application/json");
        return result;
    }

    /**
     * 分页查询故障数据
     */
    @SuppressWarnings("serial")
    public static String getFaultList(Map<String, String> paramMap) {
        String url = ARTEMIS_PATH + "/api/businessData/v2/getFault";
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", url);
            }
        };
        String result = ArtemisHttpUtil.doPostStringArtemis(path, JSON.toJSONString(paramMap), null, null, "application/json");
        return result;
    }

    /**
     * 直连海康
     */
    public static String directConnectionHik(String url, Map<String, String> paramMap) {
        String mUrl = ARTEMIS_PATH + url;
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                put("https://", mUrl);
            }
        };
        String result = ArtemisHttpUtil.doPostStringArtemis(path, JSON.toJSONString(paramMap), null, null, "application/json");
        return result;
    }

}
